#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2025 Huawei Technologies Co., Ltd. All rights reserved.

from ansible.module_utils.basic import AnsibleModule

from openubmc_ansible.openubmc_logger import report
from openubmc_ansible.openubmc_logger import log
from openubmc_ansible.openubmc_redfish_api.api_manage_account import delete_account
from openubmc_ansible.openubmc_redfish_api.redfish_base import BmcBaseConnect
from openubmc_ansible.utils import ansible_bmc_run_module


ANSIBLE_METADATA = {'metadata_version': '1.1',
                    'status': ['preview'],
                    'supported_by': 'community'}

DOCUMENTATION = r'''
---
module: openubmc_delete_account
short_description: Delete an openUBMC user
version_added: "2.5.0"
description:
    - Delete an openUBMC user
options:
    openubmc_ip:
        required: true
        default: None
        description:
            - openUBMC IP address
    openubmc_user:
        required: true
        default: None
        description:
            - openUBMC user name used for authentication
    openubmc_pswd:
        required: true
        default:
        description:
            - openUBMC user password used for authentication
    delete_account:
        required: true
        default: None
        description:
            - The openUBMC user name to be deleted
'''

EXAMPLES = r'''
- name: delete openubmc account
  openubmc_delete_account :
    openubmc_ip: "{{ openubmc_ip }}"
    openubmc_user: "{{ openubmc_user }}"
    openubmc_pswd: "{{ openubmc_pswd }}"
    delete_account: "test"
'''

RETURNS = r'''
    "msg": "Account deleted successfully!"
'''


def openubmc_delete_account_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        ret = {"result": False, "msg": 'not run delete account yet'}
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    ret = {"result": False, "msg": 'not run delete account yet'}
    with BmcBaseConnect(module.params, log, report) as openubmc:
        ret = delete_account(openubmc, module.params["delete_account"])
    return ret


def main():
    module = AnsibleModule(
        argument_spec={
            "openubmc_ip": {"required": True, "type": 'str'},
            "openubmc_user": {"required": True, "type": 'str'},
            "openubmc_pswd": {"required": True, "type": 'str', "no_log": True},
            "delete_account": {"required": True, "type": 'str'}
        },
        supports_check_mode=False)
    ansible_bmc_run_module(openubmc_delete_account_module, module, log, report)


if __name__ == '__main__':
    main()
